package com.ruanmou.house.housecommon.common;

public class ApiResponse {
    /**
     * 状态码
     */
    private int code;
    /**
     * 消息
     */
    private String message;
    /**
     * 返回的数据
     */
    private Object data;

    public ApiResponse(int code, String message, Object data) {
        this.code=code;
        this.message=message;
        this.data=data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    /**
     * 定制常用的精通方法
     */
    public static ApiResponse ofSuccess(Object data){
        return new ApiResponse(Status.SUCCESS.getCode(),Status.SUCCESS.getStandardMessage(),data);

    }
    public static ApiResponse ofMessage(int code,String message){
        return new ApiResponse(code,message,null);
    }
    public static ApiResponse ofStatus(Status status){
        return new ApiResponse(status.SUCCESS.getCode(),status.SUCCESS.getStandardMessage(),null);
    }
    /**
     * 状态枚举
     */
    public enum Status{
        SUCCESS(200,"OK"),
        BAD_REQUEST(400,"Bad Request"),
        NOT_FOUND(404,"page not found"),
        INTERNAL_SERVER_ERROR(500,"server inrernal error"),
        NOT_LOGIN(40005,"not login"),
        INVALID_PARAM(40006,"invalid parametes");

        private int code;
        private String standardMessage;
        Status(int code,String standardMessage){
            this.code=code;
            this.standardMessage=standardMessage;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getStandardMessage() {
            return standardMessage;
        }

        public void setStandardMessage(String standardMessage) {
            this.standardMessage = standardMessage;
        }
    }
}
